package com.lzc.tlmail.tlmailorder.listener;

import com.lzc.common.to.LockStockTastTO;
import com.lzc.common.to.mq.Orderto;
import com.lzc.tlmail.tlmailorder.service.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author lzc
 * @create 2020-10-22 20:09
 */
@Service
@RabbitListener(queues = "order.release.order.queue")
public class OrderListener {

    @Autowired
    private OrderService orderService;

    /**
     * 处理订单下单功能
     * @param message
     * @param orderto
     * @param channel
     */
    @RabbitHandler
    public void orderHandler(Message message, Orderto orderto, Channel channel) throws IOException {
        try {
            //关单功能 就是改变状态
            orderService.updateOrderStatus(orderto);
            //channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }catch (Exception e){
            //channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
        }
    }
}
